import {resetPwd} from '../services/API';
import { clearMenu,clearLoginToken } from '../utils/utils';
import { message } from 'antd';
export default {
    namespace:"changePassword",
    state:{
        
    },
    effects: {
        *resetPwd(payload,{call,put,select}){
            const userInfo = yield select(state =>{
                return (state.login.userInfo ? state.login.userInfo : JSON.parse(localStorage.getItem('userInfo')) )
            });
            const res = yield call(resetPwd,{...userInfo,...payload.payload});
            if(res.code === 200){
                message.success(res.msg || 'Operation succeeded');
                clearLoginToken();
                clearMenu();
                localStorage.removeItem('userInfo');
               
                
            }else{
                message.error(res.msg || '失败')
            }

        }

    },
    subscriptions: {
        setup({ dispatch, history }) {
          history.listen(({ pathname }) => {
            // if (pathname === '/index') {
              
            // }
          });
        },
      }

}